<?php

namespace StudyBuddy;

/**
 *
 * Concrete class represents answer data submitted
 * via Web via Answer form
 */
class SubmittedAnswerWWW extends SubmittedAnswer {

    /**
     * Data submitted via answer form
     *
     * @var array
     */
    protected $aData;

    /**
     *
     * Constructor
     * @param Registry $oRegistry
     * @param array $aData array submitted via Answer form
     */
    public function __construct(Registry $oRegistry, array $aData) {
        $this->oRegistry = $oRegistry;
        $this->aData = $aData;
    }

    /**
     * (non-PHPdoc)
     * @see StudyBuddy.SubmittedAnswer::getUserObject()
     */
    public function getUserObject() {
        return $this->oRegistry->Viewer;
    }

    /**
     * (non-PHPdoc)
     * @see StudyBuddy.SubmittedAnswer::getIP()
     */
    public function getIP() {
        return Request::getIP();
    }

    /**
     * (non-PHPdoc)
     * @see StudyBuddy.SubmittedAnswer::getBody()
     */
    public function getBody() {
        if (!isset($this->oBody)) {
            $this->oBody = Utf8String::factory($this->aData['qbody']);
        }

        return $this->oBody;
    }

    /**
     * The aData is guaranteed to have a value of qid because
     * it's a required form element, so we can just be sure
     * it's there!
     *
     * @return int id of question for which this is an anwser
     *
     * (non-PHPdoc)
     * @see SubmittedAnswer::getQid()
     */
    public function getQid() {
        return (int) $this->aData['qid'];
    }

    public function getExtraData() {
        return $this->oRegistry->Geo->Location->data;
    }

}
